package com.hb.game.pk.adpter;

import android.app.Activity;
import android.text.SpannableStringBuilder;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hb.game.pk.R;
import com.hb.game.pk.beans.ErBaZhuangJiaInfo;
import com.hb.game.pk.ui.activity.game.erba.ErBaRecordActivity;
import com.hb.game.pk.utils.LogUtils;
import com.hb.game.pk.utils.SpannableStringUtils;
import com.hb.game.pk.utils.StringUtils;

public class ErBaTypeRecordListAdapter extends BaseQuickAdapter<ErBaZhuangJiaInfo.DataBean, BaseViewHolder> {
    private Activity act;

    public ErBaTypeRecordListAdapter(int layoutResId, Activity act) {
        super(layoutResId);
        this.act = act;
    }

    @Override
    protected void convert(BaseViewHolder helper, ErBaZhuangJiaInfo.DataBean item) {
        helper.setText(R.id.tv_xz_title, "上庄金额");
        helper.setText(R.id.tv_zj_title, "本局输赢");
        SpannableStringBuilder spannableStringBuilder = null;
        int t_num = item.getNum();
        String num = "";
        if (t_num < 10) {
            num = t_num + "点";
        } else if (t_num >= 10 && t_num < 100) {
            num = "对子";
        } else if (t_num == 100) {
            num = "28杠";
        }
        String hb_money = "0";
        if (!StringUtils.isEmpty(item.getHb_money())) {
            hb_money = String.format("%.2f", Float.parseFloat(item.getHb_money()) / 100f);
            String[] split = hb_money.split("\\.");
            spannableStringBuilder = SpannableStringUtils.getBuilder(split[0])
                    .setForegroundColor(act.getResources().getColor(R.color.c_ffffff))
                    .append("." + split[1])
                    .setForegroundColor(act.getResources().getColor(R.color.c_fd453b))
                    .append("/" + num)
                    .setForegroundColor(act.getResources().getColor(R.color.c_ffffff))
                    .create();
        } else {
            spannableStringBuilder = SpannableStringUtils.getBuilder("0/" + num)
                    .setForegroundColor(act.getResources().getColor(R.color.c_ffffff))
                    .create();
        }
        TextView view = (TextView) helper.getView(R.id.tv_lingbao);
        view.setText(spannableStringBuilder);
        helper.setText(R.id.tv_kj_num, String.format(act.getResources().getString(R.string.item_erba_qihao), item.getChang_id()));
        helper.setText(R.id.tv_xz_val, hb_money);
        helper.setText(R.id.tv_zj_val, String.format("%.2f", Float.parseFloat(item.getShuying()) / 100f));
    }
}
